home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / newlooklib.lha / newlook / createslider.c < prev    next >
C/C++ Source or Header  |  1993-10-24  |  5KB  |  173 lines

  1. /*
  2.  *  CREATESLIDER.C
  3.  */
  4.  
  5. #include "newlook.h"
  6.  
  7. struct Gadget *CreateSlider(x,y, n, type, id)
  8. SHORT x,y, n;
  9. STRPTR type;
  10. USHORT id;
  11. {
  12.   struct Gadget *s, *a[2];
  13.   struct PropInfo *pi;
  14.   struct Border *b;   /* will always get chained to a[0] */
  15.   struct Image *i;    /* does not need to be initialized for s */
  16.   STRPTR atype[2];
  17.  
  18.   SHORT bx,by,  /* Border position (relative to a[0]) */
  19.         bw,bh;  /* Border width and height (not allways used) */
  20.  
  21.   ULONG UserHandle= SetNewLookHandle(PRIVATE_HANDLE);
  22.  
  23.   /* arrow types */
  24.  
  25.   atype[0]= atype[1]= (STRPTR)NULL;
  26.  
  27.   if(type)
  28.   {
  29.     switch(*type)
  30.     {
  31.       case 'L': case 'R':
  32.         atype[0]= "W";
  33.         atype[1]= "E";
  34.         break;
  35.       case 'l': case 'r':
  36.         atype[0]= "w";
  37.         atype[1]= "e";
  38.         break;
  39.       case 'T': case 'B':
  40.         atype[0]= "N";
  41.         atype[1]= "S";
  42.         break;
  43.       case 't': case 'b':
  44.         atype[0]= "n";
  45.         atype[1]= "s";
  46.         break;
  47.     }
  48.   }
  49.  
  50.   if(atype[0] && atype[1])
  51.   {
  52.     if(pi= (struct PropInfo *)SmartAllocate(PROPINFOSIZE))
  53.     {
  54.       if(i= (struct Image *)SmartAllocate(IMAGESIZE))
  55.       {
  56.         if(s= (struct Gadget *)SmartAllocate(GADGETSIZE))
  57.         {
  58.           if(a[0]= CreateArrowButton(x,y, atype[0], id+1))
  59.           {
  60.             if(a[1]= CreateArrowButton(x,y, atype[1], id+2))
  61.             {
  62.               pi->Flags      = AUTOKNOB|PROPBORDERLESS;
  63.               pi->HorizPot   = 0x0000;
  64.               pi->VertPot    = 0x0000;
  65.               pi->HorizBody  = 0x0000;
  66.               pi->VertBody   = 0x0000;
  67.  
  68.               /* rest set and maintained by Intuition */
  69.               pi->CWidth     =
  70.               pi->CHeight    =
  71.               pi->HPotRes    =
  72.               pi->VPotRes    =
  73.               pi->LeftBorder =
  74.               pi->TopBorder  = (UWORD)0L;
  75.  
  76.               switch(*type)
  77.               {
  78. /* h */         case 'R': case 'r':
  79.                   pi->Flags |= FREEHORIZ;
  80.                   bw= n - a[0]->Width - a[1]->Width;
  81.                   bh= a[0]->Height;  /* == a[1]->Height */
  82.                   bx= -bw;
  83.                   by= 0;
  84.                   break;
  85.                 case 'L': case 'l':
  86.                   pi->Flags |= FREEHORIZ;
  87.                   bx= a[0]->Width + a[1]->Width;
  88.                   bw= n - bx;
  89.                   bh= a[0]->Height;  /* == a[1]->Height */
  90.                   by= 0;
  91.                   break;
  92. /* v */         case 'B': case 'b':
  93.                   pi->Flags |= FREEVERT;
  94.                   bw= a[0]->Width; /* == a[1]->Width */
  95.                   bh= n - a[0]->Height - a[1]->Height;
  96.                   bx= 0;
  97.                   by= -bh;
  98.                   break;
  99.                 case 'T': case 't':
  100.                   pi->Flags |= FREEVERT;
  101.                   bx= 0;
  102.                   by= a[0]->Height + a[1]->Height;
  103.                   bw= a[0]->Width; /* == a[1]->Width */
  104.                   bh= n - by;
  105.                   break;
  106.               }
  107.  
  108.               if(bw < (KNOBHMIN+8))
  109.                 bw= KNOBHMIN+8;
  110.               if(bh < (KNOBVMIN+4))
  111.                 bh= KNOBVMIN+4;
  112.  
  113.               if(b= CreateBorder(bx,by, bw,bh,FALSE))
  114.               {
  115.                 AddGBorder(a[0],b);
  116.  
  117.                 s->LeftEdge      = x+4;
  118.                 s->TopEdge       = y+2;
  119.                 s->Width         = bw-8;
  120.                 s->Height        = bh-4;
  121.                 s->Flags         = GADGHCOMP;
  122.                 s->Activation    = RELVERIFY|FOLLOWMOUSE;
  123.                 s->GadgetType    = PROPGADGET;
  124.                 s->GadgetRender  = (APTR)i;
  125.                 s->SelectRender  = (APTR)NULL;
  126.                 s->GadgetText    = (struct IntuiText *)NULL;
  127.                 s->MutualExclude = (LONG)0L;
  128.                 s->SpecialInfo   = (APTR)pi;
  129.                 s->GadgetID      = id;
  130.                 s->UserData      = (APTR)NULL;
  131.  
  132.                 switch(*type)
  133.                 {
  134.                   case 'R': case 'r':
  135.                     a[0]->LeftEdge+= bw;
  136.                     a[1]->LeftEdge+= bw + a[0]->Width;
  137.                     break;
  138.                   case 'L': case 'l':
  139.                     s->LeftEdge+= a[0]->Width + a[1]->Width;
  140.                     a[1]->LeftEdge+= a[0]->Width;
  141.                     break;
  142.                   case 'B': case 'b':
  143.                     a[0]->TopEdge+= bh;
  144.                     a[1]->TopEdge+= bh + a[0]->Height;
  145.                     break;
  146.                   case 'T': case 't':
  147.                     s->TopEdge+= a[0]->Height + a[1]->Height;
  148.                     a[1]->TopEdge+= a[0]->Height;
  149.                     break;
  150.                 }
  151.  
  152.                 /* chain slider and arrows */
  153.  
  154.                 s->NextGadget    = a[0];
  155.                 a[0]->NextGadget = a[1];
  156.                 a[1]->NextGadget = (struct Gadget *)NULL;
  157.  
  158.                 MakePrivateHandlePublic(UserHandle);
  159.                 return s;
  160.               }
  161.             }
  162.           }
  163.         }
  164.       }
  165.     }
  166.   }
  167.   if(UserHandle != PRIVATE_HANDLE)
  168.   { SmartFreeAll(PRIVATE_HANDLE);
  169.     (void)SetNewLookHandle(UserHandle);
  170.   }
  171.   return (struct Gadget *)NULL;
  172. }
  173.